package com.woniiu01;

public class StudentService {
    public static Student[] Students;
    static{
        Students = new Student[3];
        Students[0] = new Student(1,"a","aaa",11,"male");
        Students[1] = new Student(2,"b","bbb",11,"male");
        Students[2] = new Student(3,"c","ccc",11,"male");
    }

    public static Student login03(String name,String pwd){
        Student stu = null;
        boolean flag=true;
        
        for(Student student : Students){
            stu = student;
            if(student.getName().equals(name)) {
                flag =true;
                break;
            }else {
                flag=false;
            }
        }
        if (flag==true){
            if(!stu.getPwd().equals(pwd)){
                throw new RuntimeException("密码错误");
            }
        }else {
            throw new RuntimeException("账号错误");
        }
        return stu;
    }



    public static Student login02(String name,String pwd){
        for(Student student : Students){
            if(student.getName().equals(name) && student.getPwd().equals(pwd)){
                return student;
            }
        }
        throw new RuntimeException("账号密码错误");
    }




    public static Student login01(String name,String pwd){
        for(Student student : Students){
            if(student.getName().equals(name) && student.getPwd().equals(pwd)){
                return student;
            }
        }
        return null;
    }
}
